#ifndef TRIANGLEWINDOW_H  
#define TRIANGLEWINDOW_H  

#include <QWindow>  

class QOpenGLContext;

class Renderer : public QObject
{
	Q_OBJECT
public:
	explicit Renderer(const QSurfaceFormat &format, Renderer *share = 0, QScreen *screen = 0);
	QSurfaceFormat format() const { return m_format; }

	public slots:
	void render(QSurface *surface, const QColor &color, const QSize &viewSize);

private:
	void initialize();

	bool m_initialized;
	QSurfaceFormat m_format;
	QOpenGLContext *m_context;
};

class TriangleWindow : public QWindow
{
	Q_OBJECT
public:
	explicit TriangleWindow(const QSharedPointer<Renderer> &renderer);

signals:
	void needRender(QSurface *surface, const QColor &color, const QSize &viewSize);

	private slots:
	void render();

protected:
	void exposeEvent(QExposeEvent *);

private:
	const QSharedPointer<Renderer> m_renderer;
};

#endif // TRIANGLEWINDOW_H  